package com.jdqzyy.noobnoob.common;

import com.jdqzyy.noobnoob.common.config.NoobWebConfigurer;
import com.jdqzyy.noobnoob.common.xss.XssFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.DispatcherType;

/**
 * @author Zyy
 * @Description:基本启动配置，所有的springboot项目的启动类都必须要继承这个启动类
 * @date 2020/11/21下午8:21
 * @slogan 天下风云出我辈，一入代码岁月催
 */
@SpringBootApplication
public class BaseApplication {
    public BaseApplication() {

    }

    @Bean
    WebMvcConfigurer configurer() {
        return new NoobWebConfigurer();
    }

    /**
     * 防止xss攻击，对xss请求进行过滤
     * @return
     */
    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        registration.setName("xssFilter");
        registration.setOrder(Integer.MAX_VALUE);
        return registration;
    }
}
